# Copyright(c) 2024 rc522_wiringpi authors ancktion under the xfocus License

cmake_minimum_required(VERSION 2.4)

project(mfrc522_wiringpi)

set(CMAKE_CXX_STANDARD 17)

set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)
set(PROJECT_VERSION_TWEAK 1)
if(MSVC)
    set(MY_VERSIONINFO_RC "VersionInfo.rc")
    configure_file("version.rc.in"
                   "${MY_VERSIONINFO_RC}")
endif()


configure_file(
    "version.h.in"
    "${CMAKE_CURRENT_SOURCE_DIR}/version.h"
)


#add project cpp
FILE(GLOB SOURCE_FILE  
	./*.cpp
)

set(CMAKE_BUILD_TYPE Release)
#set(CMAKE_BUILD_TYPE Debug)

#set(CMAKE_CXX_FLAGS "-m32")
#set(CMAKE_C_FLAGS "-m32")

add_definitions("-Wall -g -O0")

if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  set(CMAKE_BUILD_BIT "64")
elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "i686")
  set(CMAKE_BUILD_BIT "32")
else()
  set(CMAKE_BUILD_BIT "32")
endif()

SET(BASE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/run)

#set run path
SET(EXECUTABLE_OUTPUT_PATH ${BASE_OUTPUT_PATH})

set(MY_SYSTEMPROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR} CACHE STRING "lib")

SET(CMAKE_BUILD_INFOS ${CMAKE_HOST_SYSTEM_NAME}/${MY_SYSTEMPROCESSOR}/${CMAKE_BUILD_BIT})
MESSAGE(STATUS "MY SYSTEM PROCESSOR Now is " ${MY_SYSTEMPROCESSOR})
MESSAGE("build for bit " ${CMAKE_BUILD_BIT})
MESSAGE("lib subdirect :" ${CMAKE_BUILD_INFOS})
MESSAGE("source dir :" ${CMAKE_SOURCE_DIR})
MESSAGE("project bin :" ${PROJECT_BINARY_DIR})
MESSAGE("base output :" ${BASE_OUTPUT_PATH})

link_directories(
  #"${CMAKE_SOURCE_DIR}/lib/${CMAKE_BUILD_INFOS}"
)

include_directories(
  ${CMAKE_SOURCE_DIR}/
)


#各系统平台加载差异
#IF (WIN32)
#	MESSAGE(STATUS "Now is windows")
#ELSEIF (APPLE)
#	MESSAGE(STATUS "Now is Apple systens.")
#ELSEIF (UNIX)
#	MESSAGE(STATUS "Now is UNIX-like OS's.")
#ENDIF ()


link_libraries( 
    wiringPi
    )


# build execute
add_executable (${PROJECT_NAME} ${SOURCE_FILE} ${MY_VERSIONINFO_RC} )

# build shared lib
#add_library( ${PROJECT_NAME} SHARED ${SOURCE_FILE} ${MY_VERSIONINFO_RC} )

# 

#set build after
#add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/run ${CMAKE_SOURCE_DIR}/../run/bin/${PROJECT_NAME})
